package com.xiguthings.waka.service.question.impl;

import java.util.List;
import java.util.StringJoiner;

import com.xiguthings.waka.dao.DataBaseStatus;
import com.xiguthings.waka.dao.mapper.PaperQuestionMapper;
import com.xiguthings.waka.exception.BussinessException;
import com.xiguthings.waka.publicUtils.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.xiguthings.waka.po.PaperQuestion;
import com.xiguthings.waka.po.PaperQuestionExample;
import com.xiguthings.waka.po.extpo.Page;
import com.xiguthings.waka.service.question.IPaperQuestionService;

import javax.annotation.Resource;

@Service
@Transactional
public class PaperQuestionServiceImpl implements IPaperQuestionService{

	@Resource
	PaperQuestionMapper paperQuestionMapper;

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public int countByExample(PaperQuestionExample example) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public int deleteByExample(PaperQuestionExample example) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public int deleteByPrimaryKey(String id) throws Exception {
		int row = paperQuestionMapper.deleteByPrimaryKey(id);
		return row;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public int insert(PaperQuestion t) throws Exception {

		if(StringUtils.isBlank(t.getPaperId())){
			BussinessException.throwThis(CODE_EMPTY_REQUIRED,"paperId,为空；必须指定所属的试卷id");
		}
		if(t.getRank() == null){
			BussinessException.throwThis(CODE_EMPTY_REQUIRED,"必须指定排序号");
		}

		String id = StringUtils.getRandomUUID();
		t.setQuestionId(id);
//		t.setStatus(DataBaseStatus.NORMAL);
		int row = paperQuestionMapper.insert(t);
		return row;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public int insertSelective(PaperQuestion t) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<PaperQuestion> selectByExample(PaperQuestionExample example) throws Exception {
		List<PaperQuestion> list = paperQuestionMapper.selectByExample(example);
		return list;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public PaperQuestion selectByPrimaryKey(String id) throws Exception {
		PaperQuestion paperQuestion = paperQuestionMapper.selectByPrimaryKey(id);
		return paperQuestion;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public int updateByExampleSelective(PaperQuestion t, PaperQuestionExample example) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public int updateByExample(PaperQuestion t, PaperQuestionExample example) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public int updateByPrimaryKeySelective(PaperQuestion t) throws Exception {
		int row = paperQuestionMapper.updateByPrimaryKeySelective(t);
		return row;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public int updateByPrimaryKey(PaperQuestion t) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public Page selectByPage(Page pageEntity, PaperQuestionExample example) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
}
